package com.sumainfor.pc.gmio.service.impl.market;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ListMapMergeUtil;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.dao.MktFeign.ManagerMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.feign.ZuulFeign.ZuulFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 总经办相关
 * @Auther: zhlu
 * @Date: 2019/5/11 15:27
 * @Description:
 */
@Service
public class ManagerService {

    @Autowired
    ManagerMapper ManagerMapper;

    @Autowired
    ZuulFeign ZuulFeign;

    @Autowired
    ZpcMktFeign ZpcMktFeign;

    /**
     * 功能描述: 
     * 获取总经办运营部相关统计
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/11 15:29
     */
    public List<Map<String,Object>> getManagerGmioCount(Map<String,Object>params){
        //获取总经办运营部相关统计-退租统计
        List<Map<String,Object>>getManagerGmioCount2=ManagerMapper.getManagerGmioCount2(params);

        //获取总经办运营部相关统计-客户投诉
        List<Map<String,Object>>getManagerGmioCount4=ManagerMapper.getManagerGmioCount4(params);

        //获取总经办运营部相关统计-账单异常
        List<Map<String,Object>>getManagerGmioCount6=ManagerMapper.getManagerGmioCount6(params);

        //获取总经办运营部相关统计-违约金异常
        List<Map<String,Object>>getManagerGmioCount7=ManagerMapper.getManagerGmioCount7(params);

        //获取总经办运营部相关统计-强制退
        List<Map<String,Object>>getManagerGmioCount8=ManagerMapper.getManagerGmioCount8(params);

        //各服务中心
        List<Map<String,Object>> jsonResult=ZuulFeign.getPostDeptList(params);

        //初始化。先给所有服务中心给默认值
        for(Map<String,Object>map:jsonResult){
            map.put("gmioCount2",0);
            map.put("gmioCount4",0);
            map.put("gmioCount6",0);
            map.put("gmioCount7",0);
            map.put("gmioCount8",0);
        }
        //合并
        if(getManagerGmioCount2.size()>0)jsonResult= ListMapMergeUtil.ListMergeUtils(jsonResult,getManagerGmioCount2,"DeptId");
        if(getManagerGmioCount4.size()>0)jsonResult= ListMapMergeUtil.ListMergeUtils(jsonResult,getManagerGmioCount4,"DeptId");
        if(getManagerGmioCount6.size()>0)jsonResult= ListMapMergeUtil.ListMergeUtils(jsonResult,getManagerGmioCount6,"DeptId");
        if(getManagerGmioCount7.size()>0)jsonResult= ListMapMergeUtil.ListMergeUtils(jsonResult,getManagerGmioCount7,"DeptId");
        if(getManagerGmioCount8.size()>0)jsonResult= ListMapMergeUtil.ListMergeUtils(jsonResult,getManagerGmioCount8,"DeptId");
        return jsonResult;
    }


    /**
     * 功能描述:
     * 获取总经办列表详情
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/15 15:11
     */
    public JsonResult getManagerGmioCountList(Map<String,Object>params){
        JsonResult result=new JsonResult();
        String Option=params.get("Option").toString();
        PageUtils pageUtils = new PageUtils();

        List<Map<String,Object>>dateList=new ArrayList<Map<String,Object>>();
        Integer count=0;

        //获取所有的后台用户资料
        JsonResult jsonResult=ZuulFeign.getAllUserIdAndName();
        List<Map<String,Object>>getAllUserIdAndName=(List<Map<String,Object>>)jsonResult.getResult();

        //获取房源资料
        JsonResult jsonResult1=ZpcMktFeign.getAllHousingList();
        List<Map<String,Object>>getAllHousingList=(List<Map<String,Object>>)jsonResult1.getResult();

        //租客资料
        JsonResult jsonResult2=ZpcMktFeign.getTenantList();
        List<Map<String,Object>>getTenantList=(List<Map<String,Object>>)jsonResult2.getResult();

        switch (Option){
            case "2":
                count=ManagerMapper.getManagerGmioCount2Integer(params);
                if(count==0){
                    result=pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
                }else{
                    dateList=ManagerMapper.getManagerGmioCount2List(params);
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllUserIdAndName,"userId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllHousingList,"HouInfoId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getTenantList,"TenId");
                    result=pageUtils.getJsonResult(dateList, params, count);
                }
                break;
            case "4":
                count=ManagerMapper.getManagerGmioCount4Integer(params);
                if(count==0){
                    result=pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
                }else{
                    dateList=ManagerMapper.getManagerGmioCount4List(params);
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllHousingList,"HouInfoId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getTenantList,"TenId");
                    result=pageUtils.getJsonResult(dateList, params, count);
                }
                break;
            case "6":
                count=ManagerMapper.getManagerGmioCount6Integer(params);
                if(count==0){
                    result=pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
                }else{
                    dateList=ManagerMapper.getManagerGmioCount6List(params);
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllUserIdAndName,"userId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllHousingList,"HouInfoId");
                    result=pageUtils.getJsonResult(dateList, params, count);
                }
                break;
            case "7":
                count=ManagerMapper.getManagerGmioCount7Integer(params);
                if(count==0){
                    result=pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
                }else{
                    dateList=ManagerMapper.getManagerGmioCount7List(params);
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllUserIdAndName,"userId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllHousingList,"HouInfoId");
                    result=pageUtils.getJsonResult(dateList, params, count);
                }
                break;
            case "8":
                count=ManagerMapper.getManagerGmioCount8Integer(params);
                if(count==0){
                    result=pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
                }else{
                    dateList=ManagerMapper.getManagerGmioCount8List(params);
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllUserIdAndName,"userId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getAllHousingList,"HouInfoId");
                    dateList=ListMapMergeUtil.ListMergeUtils(dateList,getTenantList,"TenId");
                    result=pageUtils.getJsonResult(dateList, params, count);
                }
                break;
        }
        return result;
    }

}
